package com.yitao.cms.service.user.appUser;

import com.google.common.collect.Lists;
import com.skipper.base.service.GenericEntityService;
import com.yitao.client.dto.user.UserCardNoDto;
import com.yitao.client.model.user.QUserCardNoModel;
import com.yitao.client.model.user.UserCardNoModel;
import com.yitao.cms.utils.BaseUtils;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import java.util.List;

@Service
public class AppUserCardNoService extends GenericEntityService<UserCardNoModel, UserCardNoDto, QUserCardNoModel> {

    private BaseUtils baseUtils = BaseUtils.getInstance();

    public AppUserCardNoService(EntityManager entityManager) {
        super(entityManager);
    }

    public List<UserCardNoModel> getUserCardNoList(UserCardNoDto userCardNoDto) {
        List<UserCardNoModel> userCardNoModels = Lists.newArrayList();
        if (userCardNoDto == null || userCardNoDto.getCardNo() == null || userCardNoDto.getUserId() == null) {
            return userCardNoModels;
        }
        userCardNoModels = queryFactory.select(Q).from(Q).where(Q.cardNo.eq(userCardNoDto.getCardNo()).and(Q.userId.eq(userCardNoDto.getUserId()))).orderBy(Q.createTime.desc()).fetch();
        return userCardNoModels;
    }
}